﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Emgu.CV;
using System.Timers;
using Emgu.CV.Structure;
using System.Drawing;
using iMapa.Backend;
using iMapa.Helper;

namespace iMapa.UI.ModelView.Common
{
    class CameraCaptureViewModel :ViewModelBase
    {
        Timer timer;
        private Image<Bgr, byte> capturedImage;

        public Image<Bgr, byte> CapturedImage
        {
            get { return capturedImage; }
            set { capturedImage = value; }
        }

        public CameraCaptureViewModel()
        {
            capturedImage= new Image<Bgr,Byte>(800,600,new Bgr(Color.Green));
            timer = new Timer(50);
            timer.Elapsed += TimerTick;
            timer.AutoReset = true;
            timer.Enabled = true;
         }

        private void TimerTick(object sender, EventArgs e)
        {
            Image<Bgr,byte> tmp=CameraInput.getInstance().getImage();
            if (tmp != null)
            {
                SimulationController sc=SimulationController.getInstance();
                if (sc.SimulationRunning)
                {
                    tmp = sc.DrawCalibrationToImage(tmp); 
                }
                capturedImage = tmp;
                onPropertyChanged("CapturedImage");
            }
        }

        public void PauseCapture()
        {
            timer.Enabled = false;
        }

        public void ResumeCapture()
        {
            timer.Enabled = true;
        }
        
    }
}
